import requests
import json

def call_dify_workflow(api_key, workflow_id, input_data):
    # Dify API端点 (根据你的Dify实例地址调整)
    url = f"https://api.dify.ai/v1/workflows/run"
    
    # 请求头
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    
    # 请求体
    payload = {
        "inputs": input_data
    }
    
    try:
        response = requests.post(url, headers=headers, data=json.dumps(payload))
        response.raise_for_status()  # 检查是否有错误响应
        
        # 返回工作流执行结果
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Error calling Dify workflow: {e}")
        return None

# 使用示例
if __name__ == "__main__":
    # 替换为你的实际信息
    API_KEY = "app-O5IFkTQhMoBuxBM2O1929Uf7"
    INPUT_DATA = {
        "query": "value1",

    }
    
    result = call_dify_workflow(API_KEY, INPUT_DATA)
    if result:
        print("Workflow execution result:")
        print(json.dumps(result, indent=2))